package com.lizhi.yun.core.handler;/**
 * @program: sfrobot-html
 * @name StandPrescriptionInfoHandler
 * @description:
 * @author: lizhi
 * @create: 2020-05-15 14:14
 */

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.stand.dao.StandPrescriptionActionDao;
import com.lizhi.yun.db.stand.dao.StandPrescriptionInfoDao;
import com.lizhi.yun.db.stand.pojo.StandPrescriptionActionPOJO;
import com.lizhi.yun.db.stand.pojo.StandPrescriptionInfoPOJO;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.StringUtils;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@program: sfrobot-html
 *@name StandPrescriptionInfoHandler
 *@description:
 *@author: lizhi
 *@create: 2020-05-15 14:14
 */
@Slf4j
@Service
public class ServicePrescriptionInfoHandler extends NewBaseHandler {

    @Resource
    private StandPrescriptionInfoDao standPrescriptionInfoDao;

    @Resource
    private StandPrescriptionActionDao standPrescriptionActionDao;

    /**
     *功能描述  分页查询
     * @author lizhi
     * @date 2020/5/15
     * @param json:
     * @return com.lizhi.common.base.PagerView<com.lizhi.db.pojo.StandPrescriptionInfoPOJO>
     */
    public ListResponseResult doMain(String json){
        Map<String, Object> map = SamJsonUtil.toMap(json);
        PageBounds pageBounds = getPageBounds(map);
        List<StandPrescriptionInfoPOJO> list = standPrescriptionInfoDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

    /**
     *功能描述 根据处方id查询处方信息以及处方记录
     * @author lizhi
     * @date 2020/5/15
     * @param json:
     * @return com.lizhi.db.pojo.StandPrescriptionInfoPOJO
     */
    public ListResponseResult selectById(String json){
        Map<String, Object> map = SamJsonUtil.toMap(json);
        String preId = map.get("preId").toString();
        String hospitalId = map.get("hospitalId").toString();
        String hospitalSystemId = map.get("hospitalSystemId").toString();
        /*大的处方信息*/
        StandPrescriptionInfoPOJO standPrescriptionInfoPOJO = standPrescriptionInfoDao.selectById(preId, hospitalId, hospitalSystemId);
        if (StringUtils.isEmpty(standPrescriptionInfoPOJO)){
            return getListResult("未查询到处方信息", false);
        }
        /*该处方下的所有处方记录*/
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("preId", preId);
        List<StandPrescriptionActionPOJO> standPrescriptionActionPOJOS = standPrescriptionActionDao.selectByMap(paramMap, null);
        standPrescriptionInfoPOJO.setStandPrescriptionActionPOJOS(standPrescriptionActionPOJOS);
        return getListResult(standPrescriptionInfoPOJO);
    }
}
